/**
 *
 */
package com.yangtao.prototype.system.organization.web;

import com.yangtao.framework.dojo.DojoDataModel;
import com.yangtao.framework.util.Struts2Utils;
import com.yangtao.framework.web.struts2.BaseAction;
import com.yangtao.prototype.system.domain.Organization;
import com.yangtao.prototype.system.organization.service.OrganizationService;
import org.apache.commons.lang.StringUtils;

/**
 * @author 杨涛
 */
public class OrganizationAction extends BaseAction<OrganizationModel, OrganizationService> {

	/**
	 *
	 */
	private static final long serialVersionUID = 1L;

	public String init() {
		return render("OrganizationQuery");
	}

	public String initTree() {
		return render("OrganizationTree");
	}

	public String loadTree() {
		model = service.findOrganizationTree(model);
		DojoDataModel dataModel = new DojoDataModel();
		dataModel.setItems(model.getOrganizationStore());
		Struts2Utils.renderJson(dataModel, true);
		return null;
	}

	public String load() {
		if (StringUtils.isEmpty(model.getOrganization().getId())) {
			return render("OrganizationAdd");
		}
		model = service.loadOrganization(model);
		return render("OrganizationUpdate");
	}

	public String add() {
		service.addOrganization(model);
		Organization organization = model.getOrganization();
		organization.setRoles(null);
		organization.setSubOrganization(null);
		organization.setSupOrganization(null);
		organization.setUsers(null);
		return renderJson(organization);
	}

	public String update() {
		model = service.updateOrganization(model);
		Organization organization = model.getOrganization();
		organization.setRoles(null);
		organization.setSubOrganization(null);
		organization.setSupOrganization(null);
		organization.setUsers(null);
		return renderJson(organization);
	}

	public String delete() {
		service.deleteOrganization(model);
		return renderJsonMessage();
	}

	public String list() {
		service.list(model);
		return render("OrganizeList");
	}

}
